﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

/// <summary>
/// 抽象工厂模式
/// </summary>
namespace Design
{
    /// <summary>
    /// 常量
    /// </summary>
    public class Constant
    {
        //基本工资
        public static double Basic_Salary = 4000;

        //读取配置通过反射构造对象        
        public static string str_factoryName = ConfigurationSettings.AppSettings["factoryName"].ToString();
    }


    //奖金抽象类
    public abstract class Bonus
    {
        /// <summary>
        /// 计算奖金抽象方法
        /// </summary>
        /// <returns></returns>
        public abstract double Calculate();
    }

    /// <summary>
    /// 计算奖金 （美国）
    /// </summary>
    public class AmericanBonus : Bonus
    {
        /// <summary>
        /// 美国 计算奖金 基本工资*15%
        /// </summary>
        /// <returns></returns>
        public override double Calculate()
        {
            return Constant.Basic_Salary * 0.15;
        }
    }

    /// <summary>
    /// 计算奖金 （中国）
    /// </summary>
    public class ChineseBonus : Bonus
    {
        /// <summary>
        /// 中国 计算奖金 基本工资*10%
        /// </summary>
        /// <returns></returns>
        public override double Calculate()
        {
            return Constant.Basic_Salary * 0.1;
        }
    }

    /// <summary>
    /// 个人所得税抽象类
    /// </summary>
    public abstract class Tax
    {
        /// <summary>
        /// 计算个人所得税抽象类
        /// </summary>
        /// <returns></returns>
        public abstract double Calculate();
    }

    /// <summary>
    /// 计算个人所得税 美国
    /// </summary>
    public class AmericanTax : Tax
    {
        public override double Calculate()
        {
            return (Constant.Basic_Salary * 0.05) + (Constant.Basic_Salary * 0.15 * 0.25);
        }
    }

    /// <summary>
    /// 个人所得税 中国
    /// </summary>
    public class ChineseTax : Tax
    {
        /// <summary>
        /// 个人所得税  （基本工资+奖金）* 40%
        /// </summary>
        /// <returns></returns>
        public override double Calculate()
        {
            return (Constant.Basic_Salary + (Constant.Basic_Salary * 0.1)) * 0.4;
        }
    }

    public abstract class CreateAbstractFactory
    {
        public abstract Tax CreateTax();
        public abstract Bonus CreateBonus();
    }

    public class AmericanFactory : CreateAbstractFactory
    {
        public override Tax CreateTax()
        {
            return new AmericanTax();
        }

        public override Bonus CreateBonus()
        {
            return new AmericanBonus();
        }
    }
    public class ChineseFactory : CreateAbstractFactory
    {

        public override Tax CreateTax()
        {
            return new ChineseTax();
        }

        public override Bonus CreateBonus()
        {
            return new ChineseBonus();
        }
    }



    //计算
    public class Calculator
    {
        public void Sum()
        {
            Bonus bonus = new ChineseBonus();
            Tax tax = new ChineseTax();

            double salary = Constant.Basic_Salary + bonus.Calculate() - tax.Calculate();
            Console.Write("中国工资："+salary);
        }
    }


}
